
public class SymbolTableEntry {

	private String name = null;
	private int type = -1;
	private String value = null;
	private int offset = 0;
	private int width = 0;
	private boolean parameter = false;
	private SymbolTable forward = null;
	
	/*
	    Integer = 0;
        Double = 1;
	    Boolean = 2;
	 */

	private SymbolTableEntry() {
		super();
	}

	private SymbolTableEntry(String name) {
		this();
		this.name = name;
	}
	
	public SymbolTableEntry(int datatype, String name, int offset) {
		
		this(name);
		
		int size=0;
		//Datatype Integer
		if(datatype == 0)
			size = 4;
		//Datatype Double
		if(datatype == 1)
			size = 8;
		//Datatype Boolean
		if(datatype == 2)
			size = 1;
		
		this.setType(datatype);
		this.setOffset(offset);
		this.setWidth(size);
	}

	public SymbolTableEntry(String name, int value, int offset) {
		this(name);
		this.setType(0);
		this.setValue(value);
		this.setOffset(offset);
		this.setWidth(4);
	}

	public SymbolTableEntry(String name, double value, int offset) {
		this(name);
		this.setType(1);
		this.setValue(value);
		this.setOffset(offset);
		this.setWidth(8);
	}

	public SymbolTableEntry(String name, boolean value, int offset) {
		this(name);
		this.setType(2);
		this.setValue(value);
		this.setOffset(offset);
		this.setWidth(1);
	}
	
	public SymbolTableEntry(int datatype, String name, int offset, boolean parameter) {
		this(datatype, name, offset);
		this.parameter = parameter;
	}
	
	public SymbolTableEntry(String name, int value, int offset, boolean parameter) {
		this(name, value, offset);
		this.parameter = parameter;
	}
	
	public SymbolTableEntry(String name, double value, int offset, boolean parameter) {
		this(name, value, offset);
		this.parameter = parameter;
	}
	
	public SymbolTableEntry(String name, boolean value, int offset, boolean parameter) {
		this(name, value, offset);
		this.parameter = parameter;
	}

	public SymbolTableEntry(String name, SymbolTable forward, int offset) {
		this(name);
		this.setOffset(offset);
		this.setType(3);
		this.setForward(forward);
	}

	public String getName() {
		return this.name;
	}

	public int getType() {
		return this.type;
	}

	public int getOffset() {
		return this.offset;
	}
	
	public boolean getParameter() {
		return this.parameter;
	}

	public SymbolTable getForward() {
		return this.forward;
	}
	
	public int getValueInteger() {
		return Integer.parseInt(this.value);
	}
	
	public double getValueDouble() {
		return Double.parseDouble(this.value);
	}
	
	public boolean getValueBoolean() {
		return Boolean.parseBoolean(this.value);
	}
	
	public String getValueText() {
		return this.value;
	}
	
	public int getWidth() {
		return this.width;
	}

	public void setName(String name) {
		if(name != null && name.length() > 0)
			this.name = name;
	}

	public void setType(int type) {
		if(type >= 0 && type <= 3)
			this.type = type;
	}

	public void setOffset(int offset) {
		if(offset >= 0)
			this.offset = offset;
	}
	
	public void setParameter(boolean parameter) {
		this.parameter = parameter;
	}

	public void setForward(SymbolTable forward) {
		if(forward != null)
			this.forward = forward;
	}

	public void setValue(int value) {
		this.value = String.valueOf(value);
	}

	public void setValue(double value) {
		this.value = String.valueOf(value);
	}

	public void setValue(boolean value) {
		this.value = String.valueOf(value);
	}

	public void setValue(String value) {
		if(this.value != null && this.value.length() > 0)
			this.value = String.valueOf(value);
	}
	
	public void setWidth(int width) {
		this.width = width;
	}

	public String getSymbolTableEntryHTMLFormat() {
		String ret = "<tr>";
		ret += "<td>" + this.name + "</td>";
		ret += "<td>" + decodeType(this.type) + "</td>";
		ret += "<td>" + (this.value != null ? this.value : "") + "</td>";
		ret += "<td>" + this.offset + "</td>";
		ret += "<td>" + this.width + "</td>";
		ret += "<td>" + (this.forward != null ? this.forward : "") + "</td>";
		ret += "</tr>";
		return ret;
	}

	private String decodeType(int type) {
		switch(type) {
			case 0:
				return "Integer";
			case 1:
				return "Double";
			case 2:
				return "Boolean";
			default:
				return "Scope";
		}
	}
}
